package com.sky.happygos.ui.activity.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sky.happygos.R;

import java.util.List;

/**
 * Created by qqqqqqq on 2017/4/14.
 */

public class ShopAdapter extends RecyclerView.Adapter{
    private static final int FOOTER = 1;
    private static final int NOMAL = 0;

    public Context context;
    public LayoutInflater layoutInflater;
    public List<String> list;
    public MyItemClickListener myItemClickListener;

    public interface MyItemClickListener {
        public void onItemClick(View view,int postion);
    }


    public ShopAdapter(Context context,List<String> list){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.list = list;
    }

    public void setMyItemClickListener(MyItemClickListener myItemClickListener){
        this.myItemClickListener = myItemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == NOMAL) {
            return new ShopHolder(layoutInflater.inflate(R.layout.item_shop, null),myItemClickListener);
        }
        if(viewType == FOOTER){
            return new FooterHolder(layoutInflater.inflate(R.layout.item_shop_foot, null));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ShopHolder) {
            ((ShopHolder) holder).bindData();
        }
    }

    @Override
    public int getItemViewType(int position) {
        if(position == list.size()){
            return FOOTER;
        }
        return NOMAL;
    }

    @Override
    public int getItemCount() {
        return list.size()+1;
    }

    class ShopHolder extends RecyclerView.ViewHolder{

        MyItemClickListener myItemClickListenerr;

        public ShopHolder(View itemView, final MyItemClickListener myItemClickListener) {
            super(itemView);
            this.myItemClickListenerr = myItemClickListener;
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    myItemClickListenerr.onItemClick(v,getPosition());
                }
            });
        }

        public void bindData(){

        }
    }
    class FooterHolder extends RecyclerView.ViewHolder{

        public FooterHolder(View itemView) {
            super(itemView);
        }

        public void bindData(){

        }
    }
}
